﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace PhotoBackupWS
{
    public class Generator
    {

        Random random = new Random();

        private int RandomNumber(int min, int max)
        {
            return random.Next(min, max);
        }


        private string RandomString(int size, bool lowerCase)
        {
            StringBuilder builder = new StringBuilder();
            char ch;
            for (int i = 0; i < size; i++)
            {
                ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
                builder.Append(ch);
            }
            if (lowerCase)
                return builder.ToString().ToLower();
            return builder.ToString();
        }

        public string Generate(int length)
        {
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < length; i++)
            {
                int valueType = RandomNumber(1, 3);
                switch (valueType)
                {
                    case 1:
                        builder.Append(RandomNumber(0, 9));
                        break;
                    case 2:
                        builder.Append(RandomString(1, true));
                        break;
                    case 3:
                        builder.Append(RandomString(1, false));
                        break;
                }
            }

            return builder.ToString();
        }
    }
}
